Skip to content

perf(video): shorten the docked 1080p picture lane - #13

Merged
enricobuehler merged 6 commits into
mainfrom
perf/docked-1080p
Nov 5, 2026
Merged

enricobuehler merged 6 commits into
mainfrom
perf/docked-1080p

Conversation

@enricobuehler

Copy link
Copy Markdown
Member

Docked 1080p60 did not fit a frame: each picture ran NVDEC, a VIC transfer, a 3 MB CPU copy into uncached staging and a staging copy on the GPU, one after another, with NVDEC under-clocked by nvtegra's scaling and the UI layer composited every frame.

What changes

  • The UI layer is skipped while the overlay is empty (a2f4b47).
  • NVDEC holds its top clock while docked (b3380d1, then 08e8a01). nvtegra's scaling puts a 1080p picture at about 8 ms. Handheld keeps that scaling by default; the dock state is asked at each access unit, so a dock change mid-stream moves the clock. nvdec[10s] now shows the clock.
  • Pictures in place (c65be0a). Each NVDEC surface is imported once (VK_EXT_external_memory_host) and the new tiled CSC pass detiles its 16Bx2 block-linear planes as it samples. No VIC transfer, no copy, no upload.
    • Each decoder starts on the VIC. Its first detailed picture is read back through the GPU at the addresses the shader samples and compared with the VIC's copy; only a match moves the lane in place. A mismatch, an unsampleable surface or a failed import moves it back for good, with a log line.
    • A file vic-copia in /switch/punktfunk/ keeps the VIC route for an A/B. vic-direto (straight VIC) also keeps it.
  • pf-nx-sys links libavcodec after the shim (5db41e6): its tests did not link on their own on Debian.

Checked

  • Linux (host image): clippy -D warnings, cargo test --workspace. New lavapipe tests in pf-nx-vk/tests/in_place.rs draw a block-linear surface through the tiled pass against the same picture through the NV12 upload: within 3 LSB at 1:1 and 8 scaled (the upload's 8-bit sampler against the pass's float filter); a pitch-linear surface misses by more than 32; the read-back check tells the two layouts apart.
  • Console: cargo-nx.sh check -p pf-nx -p pf-nx-probe and the NRO build.
  • Rejected: NVK's NvMap-ID import (it refuses IDs it did not make) and a coherent import (it would make the decoder's pages uncached).

Not proven: the console run

  1. Docked, 1080p60 stream. The log should show in place: picture … read back as the VIC wrote it; pictures now go in place, then nvdec[10s] with route in place, and the picture right.
  2. If it says read back otherwise or back to the VIC, that line is the finding; the stream keeps running on the VIC.
  3. Handheld: nvdec[10s] shows nvtegra's own clock, not the top one.
  4. A/B: vic-copia on the SD card, same stream.

nvtegra rescales NVDEC every 20 pictures so that one takes about a frame
interval, with a 180 MHz floor up to 1080p. That is playback's rule. In a
stream it left a 1080p picture 7.6 ms of decode, and with the VIC transfer
and the copy the lane filled the 60 Hz frame: docked play fell behind.

Above 720p the shim asks the decoder's own clock request for the top rate
again after each rescale, and closing the decoder releases it. Handheld
keeps the scaling: 720p fits there, and the clock costs battery.

The nvdec line carries NVDEC's clock, so a console run shows what each
window decoded at.
Every stream frame cleared the full-screen UI image, flushed Skia and
blended the layer over the picture, though with stats off and the dial
closed it held nothing. At 1080p that is three full-screen passes on the
memory bus that NVDEC, the VIC and the copy share.

The stream now tells the display when its overlay is empty, and the
presenter skips the draw, the flush and the blend. Leaving the stream turns
the layer back on.
The handheld clock needs the maintainer's yes; sampling the decoded surface
in place needs a console probe first.
pkg-config's link flags came out before the shim's own archive. With
--as-needed, as on Debian's toolchain, the linker dropped libavcodec
before anything used it, so the crate's own tests did not link alone.
Naming the libraries after the shim keeps them.
The stream's size was the wrong gate: a handheld 1080p stream took the
top clock and its battery cost. Docked, the console is on mains and the
1080p picture needs the headroom. Handheld keeps nvtegra's own scaling,
which already decodes 720p in about 4 ms.

The lane asks at each access unit, so a dock change mid-stream moves the
clock without a new decoder. Turning it off hands NVDEC back to
nvtegra's scaling at its next rescale.
At docked 1080p each picture paid a VIC transfer (seven nvdrv calls and
a 3 MB cache flush), then a 3 MB copy into uncached staging, then a
staging copy on the GPU. That serial lane was most of why 1080p60 did
not fit a frame. The presenter now imports each decoder surface once
as host memory and detiles its block-linear planes as it samples them.

A layout or import the console does not honour would show a wrong
picture, so each decoder starts on the VIC. Its first detailed picture
is read back through the GPU at the addresses the shader samples and
compared with the VIC's copy; only a match moves the lane in place, and
any later failure moves it back for good. A vic-copia file keeps the
VIC for an A/B.

Imports carry the decoder's pool generation: a replaced pool may free
addresses a new one reuses.
@enricobuehler

Copy link
Copy Markdown
Member Author

Merging over the red console / console check. It failed at "Toolchain image": pkg.devkitpro.org answers 403 to every request right now (the runner's dkp-pacman -Syu and a check from outside alike), before any of this branch compiles. The same NRO build (cargo-nx.sh build -p pf-nx + package-nro.sh) passed locally on this tree with the pinned toolchain image built before the outage; host passed here.

CI could not hand out the NRO anyway: the account's artifact storage quota is full. To test: pull main and build with an existing toolchain image, or use a build passed on directly.

@enricobuehler
enricobuehler merged commit f4bd35b into main Nov 5, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant